{include file="common::header"/}
<style type="text/css">
    .header {
        background: transparent;
    }

    .header a {
        color: white;
    }

    .header li.active a {
        color: white;
        border-bottom: 4px solid white;
    }

    .head_reg a {
        background: transparent;
    }
    .get-tips{
        color: #464646;
    }
    pre {
         background-color: #292b36;
         color: #ffffff;
         padding: 10px;
         border-radius: 6px;
         position: relative;
         margin: 10px 0 20px 0;
     }
</style>
<link rel="stylesheet" href="__STATIC__/index/css/get.css">
<div class="banner get_banner">
    <div class="w1200">
        <div class="get_content">
            <h3>API测试</h3>
        </div>
    </div>
</div>
<div class="get_sub">
    <div class="get_title"><p>API测试</p></div>

    <div class="get_line"></div>
    <div class="get_form">
        <form class="layui-form" action="" method="post">
            <div class="layui-form-item get_form_fir">
                <label class="layui-form-label">支付方式</label>
                <div class="layui-inline">
                    <select name="channel" lay-verify="required">
                        <option value="wx_scan">免费试用 - 微信扫码支付</option>
                    </select>
                </div>
                <div class="layui-inline get-tips">
                    <svg class="icon"
                         style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden; font-size: 24px;"
                         viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1606">
                        <path d="M742.15424 821.53344C675.26656 871.35872 595.68 897.69472 512 897.69472c-212.67328 0-385.696-173.02272-385.696-385.69728 0-81.248 24.95488-158.94528 72.1664-224.6912 16.49408-22.96832 11.2448-54.95936-11.72352-71.45216-22.96832-16.4928-54.95936-11.2448-71.45216 11.72352-59.78752 83.26016-91.39072 181.61024-91.39072 284.41984 0 65.87008 12.91264 129.79712 38.37696 190.00576 24.58624 58.12736 59.77216 110.32064 104.5824 155.13088 44.80896 44.80896 97.00352 79.99616 155.13088 104.5824 60.20864 25.4656 124.1344 38.37696 190.00448 38.37696 105.89056 0 206.62912-33.34912 291.32672-96.4416 22.67648-16.89216 27.3664-48.96896 10.47424-71.64672C796.91008 809.3312 764.832 804.64 742.15424 821.53344zM961.71776 321.99424c-24.58624-58.12864-59.77216-110.32192-104.5824-155.13088C812.3264 122.0544 760.13312 86.86848 702.0032 62.28224 641.79584 36.81664 577.87008 23.904 512 23.904c-105.8752 0-206.60352 33.34016-291.29216 96.416-22.67776 16.89088-27.37024 48.96768-10.47936 71.64544 16.8896 22.67776 48.96768 27.37024 71.64544 10.47936C348.75392 152.6336 428.33024 126.304 512 126.304c212.672 0 385.69472 173.02144 385.69472 385.69344 0 83.51232-26.23872 162.96704-75.87968 229.77536-16.864 22.69696-12.13568 54.76864 10.56128 71.63392 9.17504 6.81728 19.88096 10.10688 30.496 10.10688 15.64416-0.00128 31.08992-7.14496 41.13792-20.66688 62.85824-84.59904 96.08448-185.17248 96.08448-290.848C1000.09472 446.12864 987.18208 382.2016 961.71776 321.99424zM355.5712 243.97568c-24.39296 46.66368-51.4368 88.0256-93.32864 143.17312l87.4944 0c18.0288-22.272 34.46784-46.13376 49.31584-70.52672l219.0016 0c3.712 0 7.42528 2.12096 9.01504 4.77312 1.59232 3.1808 1.59232 6.8928 0.52992 10.07488l-37.64736 69.4656L315.80032 400.93568c-19.08992 0-34.99776 15.90784-34.99776 35.52896l0 97.57056c0 19.61984 15.90784 35.52896 34.99776 35.52896l120.9024 0c-36.5888 58.85952-95.97952 98.6304-165.44512 115.59936l0 60.45184c112.41856-18.0288 200.97408-74.76864 247.10784-165.97504L518.36544 709.5552c0 19.08992 15.90784 34.99904 35.52768 34.99904l207.86688 0 0-30.22592L618.5856 714.32832c-11.13472 0-19.61984-9.01376-19.61984-20.14976l0-124.61312 109.23776 0c20.14976 0 35.52768-15.90912 35.52768-35.52896l0-97.57056c0-19.62112-15.37792-35.52896-35.52768-35.52896l-36.06016 0 41.89312-77.41952c4.24192-7.95392 4.24192-16.96896-1.05984-24.92288-4.77312-7.95392-12.19712-12.19584-21.2096-12.19584L417.0816 286.39872c7.95392-13.78688 15.90912-28.10496 23.33312-42.42176L355.5712 243.97696zM452.61056 539.33696l-71.05664 0c-11.136 0-20.15104-9.01504-20.15104-20.14976l0-67.87456c0-11.136 9.01504-20.15104 20.15104-20.15104l93.85856 0C474.88128 471.4624 466.39744 507.52128 452.61056 539.33696zM663.1296 451.31264l0 67.87456c0 11.13472-9.01504 20.14976-20.15232 20.14976l-107.64544 0c11.13728-32.34688 16.97024-68.9344 18.03008-108.17536l89.61536 0C654.11456 431.1616 663.1296 440.17664 663.1296 451.31264z"
                              p-id="1607"></path>
                    </svg>
                    日最高测试20单
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">支付金额</label>
                <div class="layui-inline">
                    <div class="count">
                        <i class="leftsavecookie" id="left">-</i>
                        <span class="savecookie" id="scrollBarTxt">1</span>
                        <i class="rightsavecookie" id="right">+</i>
                    </div>
                    <input name="sum" hidden id="sum" value="1">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">支付商品</label>
                <div class="layui-input-inline">
                    <input type="text" readonly disabled class="layui-input" name="body" value="API支付测试" title="支付商品">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">支付单号</label>
                <div class="layui-input-inline">
                    <input type="text" readonly disabled class="layui-input" name="order_no" value="{:create_order_no()}" title="单号">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">报文格式</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="json" title="JSON" checked>
                </div>
            </div>
            <div class="layui-form-item get_center">
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="api-go">发起支付</button>
                </div>
            </div>
        </form>
    </div>
    <div class="get_title"><p>支付</p></div>
    <div class="get_linker">
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal get_btton_normal">POST</a>
            <input class="layui-input"
                   readonly disabled value="https://api.iredcap.cn/pay/unifiedorder" >
        </div>
        <div class="get_api_res">
            <p>参数说明（使用 <b>HTTP POST</b> 方式） :</p>
            <table>
                <thead>
                <tr>
                    <th>名称</th>
                    <th>类型</th>
                    <th>必选</th>
                    <th>说明</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>appid</td>
                    <td>string</td>
                    <td>True</td>
                    <td>后台生成的appid(<a href="/user/open/">点击前往</a>),用户登陆情况下浏览器访问本接口不需要传,其他情况必传</td>
                </tr>
                <tr>
                    <td>subject</td>
                    <td>string</td>
                    <td>True</td>
                    <td>支付项目</td>
                </tr>
                <tr>
                    <td>body</td>
                    <td>string</td>
                    <td>True</td>
                    <td>支付商品信息</td>
                </tr>
                <tr>
                    <td>amount</td>
                    <td>bigint</td>
                    <td>True</td>
                    <td>支付总金额</td>
                </tr>
                <tr>
                    <td>extra</td>
                    <td>string</td>
                    <td>True</td>
                    <td>附加参数</td>
                </tr>
                <tr>
                    <td>channel</td>
                    <td>string</td>
                    <td>True</td>
                    <td>支付方式,当前支持: wx_scan,qq_scan</td>
                </tr>
                <tr>
                    <td>currency</td>
                    <td>string</td>
                    <td>True</td>
                    <td>支付币种,当前支持: CNY</td>
                </tr>
                <tr>
                    <td>client_ip</td>
                    <td>string</td>
                    <td>True</td>
                    <td>发起支付IP</td>
                </tr>
                <tr>
                    <td>notify_url</td>
                    <td>string</td>
                    <td>True</td>
                    <td>异步通知地址</td>
                </tr>
                <tr>
                    <td>return_url</td>
                    <td>string</td>
                    <td>True</td>
                    <td>同步回调地址</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="get_title" id="response_box"><p>结果返回示例</p></div>
    <div class="get_res">
        <div class="get_res_demo">
            <p>返回数据</p>
            <div class="code">
                <pre id="response" data-type="json"></pre>
            </div>
            <p>正确返回示例</p>
            <div class="code">
            <pre data-type="json">{
    "result_code": "OK",
    "result_msg": "SUCCESS",
    "charge": {
        "channel": "wx_scan",
        "order_no": "A20180924175446924770",
        "client_ip": "112.116.253.55",
        "amount": "100",
        "currency": "CNY",
        "subject": "API支付测试",
        "body": "API支付测试",
        "extra": {
            "openid": "ow_eHIGfsQM6qGrd27qRj3v1R5fyY2PjJ0h"
        },
        "credential": {
            "prepay_id": "wx241754525235056fc4574b7d2697455231",
            "order_qr": "weixin://wxpay/bizpayurl?pr=xxxxxx"
        }
    }
}</pre>
            </div>
            <div class="h_20"></div>
            <p>错误返回示例</p>
            <div class="code">
                <pre>{
    "error_msg": "Create Order Error:[Repeat Order Number]",
    "error_code": 200001
}
                </pre>
            </div>
        </div>
        <div class="get_api_res">
            <p>结果注释 :</p>
            <table>
                <thead>
                <tr>
                    <th>名称</th>
                    <th>类型</th>
                    <th>说明</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <td>result_code</td>
                    <td>string</td>
                    <td>结果码, OK:成功; 其他:失败</td>
                </tr>
                <tr>
                    <td>result_msg</td>
                    <td>string</td>
                    <td>提示信息,SUCCESS:成功</td>
                </tr>
                <tr>
                    <td>charge</td>
                    <td>object</td>
                    <td>返回支付对象</td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
    <div class="get_title"><p>API调用说明</p></div>
    <div class="get_use_code">
        <div class="get_use_con">
            <p>* API调用请在请求头中添加键值对<span>authentication: ?</span>，其中的<span>?</span>为Appkey<span>md5(scret_key)自动生成</span></p>
            <p>* <a href="https://github.com/iredcap/pay-php">php调用示例下载</a></p>
        </div>
    </div>
    <div class="clearfix"></div>
</div>

{include file="common::footer"/}
<script src="__STATIC__/index/js/index.js"></script>
<script src="__STATIC__/index/js/clipboard.min.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/gradient.js"></script>
<script>
    layui.use(['form', 'jquery','layer'], function() {
        var form = layui.form(),
            layer = layui.layer,
            $ = layui.jquery;
        form.render();

        form.on('radio(city)', function (data) {
            $('#city_div').show();
            $('#prov_div').hide();
        });
        form.on('radio(prov)', function (data) {
            $('#city_div').hide();
            $('#prov_div').show();
        });

        //减法
        $('#left').click(function () {
            var count = Number($('#scrollBarTxt').text());
            if (count > 1) {
                count = count - 1;
                if (count < 1) {
                    layer.msg('单次提取数量不能低于1个');
                    return;
                }
                $('#scrollBarTxt').text(count);
                $('#num').val(count)
            }
        });
        //加法
        $('#right').click(function () {
            var count = Number($('#scrollBarTxt').text());
            count = count + 1;
            if (count > 10) {
                layer.msg('支付测试金额不能超过10元，使用api接口可以提取更多');
                return;
            }
            $('#scrollBarTxt').text(count);
            $('#num').val(count)
        });

        //复制
        $('#copy_link').click(function (data) {
            if ($('#api_input').val() != '') {
                new ClipboardJS('#copy_link', {
                    text: function(trigger) {
                        return $('#api_input').val();
                    }
                });
                layer.msg('复制成功');
            }
        });

        //复制
        $('#open_link').click(function (data) {
            if ($('#api_input').val() != '') {
                window.open($('#api_input').val());
            }
        });

        //提交支付
        var login = "{:is_login()}";
        form.on('submit(api-go)', function (data) {
            if (!login) {
                layer.msg('请登陆后操作');
                return false;
            }
            //加载层-风格2
            layer.load(1);
            //此处演示关闭
            setTimeout(function(){
                layer.closeAll('loading');
                //提交测试接口
                $.post("/get",data.field,function (res) {
                    layer.msg(res.msg);
                    if (res.data !== ''){
                        setTimeout(function () {
                            //下滑
                            var timer=setInterval(function(){
                                window.scrollBy(0,+30);
                                if(window.scrollY >= 1500){
                                    clearInterval(timer);
                                }
                            },10);
                            $("#response").html(JSON.stringify(res.data, null, 4));
                        },1000);
                    }

                });
            }, 1000);
            return false;
        })

    });
</script>
</body>
</html>
